<template>
  <div class="shield-wrap">
    <div class="title">拉黑理由：</div>
    <div class="shield-box">
      <textarea class="content" maxlength="30" placeholder="请输入拉黑理由" v-model="remark" @blur="inputBlur"></textarea>
    </div>

    <div class="btn-box" v-show="hideBtn">
      <button type="button" class="btn" @click="confirmPass">确定</button>
    </div>
  </div>
</template>

<script>
  import {baseUrl} from "../../../config/env"

  export default {
    data() {
      return {
        remark: "",
        id: "",
        mechanismId: "",
        docmHeight: document.documentElement.clientHeight,//默认屏幕高度
        showHeight: document.documentElement.clientHeight,//实时屏幕高度
        hideBtn: true//显示或者隐藏
      }
    },
    mounted() {
      let base64 = require('js-base64').Base64;
      this.userSign = base64.decode(sessionStorage.getItem("success"));
      this.id = this.$route.query.id;
      this.mechanismId = this.$route.query.mechanismId;

      window.onresize = () => {
        return (() => {
          this.showHeight = document.body.clientHeight;
        })()
      };
    },
    methods: {
      confirmPass() {
        if (this.remark == "" || this.remark == undefined) {
          this.$vux.toast.text("请输入拉黑理由", "middle");
          return;
        }
        this.$vux.loading.show({
          text: '加载中',
        });
        let data = {
          "type": 1,
          "status": -1,
          "id": this.id,
          "reason": this.remark
        };
        let time = (new Date()).getTime();
        let url = baseUrl + "/resident/update_work_order?timestamp=" + time;
        let param = {"sgin": this.userSign, "timestamp": time};
        let signature = this.$signature(url, param);

        //修改面试预约状态
        this.axios.post(baseUrl + "/resident/update_work_order?sgin=" + this.userSign + "&auth=" + signature + "&timestamp=" + time, data).then((res) => {
          let resultObj = res.data;
          this.$vux.loading.hide();
          if (resultObj.code == 0) {
            if (resultObj.data == 0) {
              this.$vux.toast.text("拉黑失败，请重试", "middle");
            } else {
              this.$router.push({path: "/employlist", query: {"id": this.mechanismId}});
            }
          } else {
            this.$vux.toast.text(resultObj.msg, "middle");
          }
        }).catch(() => {
          this.$vux.loading.hide();
          this.$vux.toast.text("网络异常", "middle");
        });
      },
      inputBlur() {
        window.scrollTo(0, 0);
      }
    },
    watch: {
      showHeight() {
        if (this.docmHeight > this.showHeight) {
          this.hideBtn = false;
        } else {
          this.hideBtn = true;
        }
      }
    }
  }
</script>

<style lang="stylus" scoped>
  .shield-wrap
    width: 100%
    height: 100%
    overflow: hidden
    .title
      margin-top: 0.48rem
      margin-left: 0.32rem
      margin-bottom: 0.307rem
      font-size: 0.427rem
      font-weight: 500
      color: rgba(51, 51, 51, 1)
    .shield-box
      margin: 0 auto
      width: 93.6%
      height: 2.667rem
      .content
        padding-top: 0.267rem
        padding-left: 0.267rem
        width: 97%
        height: 2.387rem
        font-size: 0.373rem
        color: rgba(51, 51, 51, 1)
        line-height: 0.48rem
        border: 0.027rem solid rgba(224, 224, 224, 1)
        border-radius: 0.053rem
        resize: none
    .btn-box
      position: absolute
      bottom: 0.64rem
      display: flex
      justify-content: center
      align-items: center
      width: 100%
      height: 1.28rem
      .btn
        width: 90.4%
        height: 1.28rem
        line-height: 1.28rem
        background: rgba(60, 175, 255, 1)
        font-size: 0.453rem
        color: rgba(255, 255, 255, 1)
        font-weight: 500
        border-radius: 0.16rem
</style>
